package com.gsx.mapper;

import com.gsx.entity.UserInfo;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {
    /*这是mybatis提供了一个使用注解来传入多个参数的方式、这种方式需要在Mapper接口的参数上添加@param注解*/
    @Select("select * from user where username=#{username} and password=#{password}")
    public UserInfo checkUser(@Param("username") String username, @Param("password") String password);

    @Select("select password from user where username=#{username}")
    public String getUser(String username);

    @Select("select user_id,nickname,username,email,avatar from user where username=#{username}")
    public UserInfo getUserInfo(String username);

    @Select("select authorities from user where username=#{username}")
    public String getAuth(String username);

    @Insert("insert into user(nickname,username,password,email) values(#{nickname},#{username},#{password},#{email})")
    public int newUser(UserInfo user);

    @Update("update user set password=#{password} where username=#{username}")
    public int updatePassword(UserInfo user);

    @Select("SELECT COUNT(blog_id) FROM blog WHERE user_id=#{user_id}")
    public int getUserBlogCont(Long user_id);

    @Update("update user set nickname=#{nickname},email=#{email},avatar=#{avatar} where user_id=#{user_id}")
    public int updateUser(UserInfo userInfo);
}
